home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
Tickle-4.0 (tcl)
/
src
/
FileInfo.c
< prev
next >
Wrap
Text File
|
1993-11-18
|
9KB
|
301 lines
#ifdef MPW3
# pragma segment FINFO
#endif
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#include "tickle.h"
#include <fcntl.h>
#include <string.h>
#include <traps.h>
#include "tge.h"
SFFileInfo()
{
Point mypoint;
SFReply myreply;
SFTypeList mytypes;
mypoint.h = mypoint.v = 75;
MyGetFile(mypoint, "\pInformation For File…", NULL, -1, mytypes, NULL, &myreply);
if (myreply.good)
FileInfo(&myreply);
}
#define FINFO_DIALOG 3098
#define dtitle1item 3
#define dtitle2item 4
#define dstypeitem 5
#define dscreatoritem 6
#define dtypeitem 7
#define dcreatoritem 8
#define lkdItem 9
#define visItem 10
#define bunItem 11
#define dskItem 12
#define initItem 13
#define bozoItem 14
#define sysItem 15
#define chgItem 16
#define shrItem 17
#define cachItem 18
#define dataItem 19
#define rsrcItem 20
#define rdoItem 21
#define dfolderitem 22
FileInfo(myReply)
SFReply *myReply;
{
short itemhit, done, save, i, myerr, myflags;
DialogPtr mydialog;
GrafPtr saveport;
char mystr[256], cstr[50], mstr[50];
/*char pathname[256];*/
ParamBlockRec myparm;
CInfoPBRec cparm; /* Used for New ROM HFS File Manager. */
extern pascal Boolean UniversalFilter();
GetPort(&saveport);
InitCursor();
mydialog = GetNewDialog(FINFO_DIALOG, NULL, inFront);
if (mydialog == NULL) {
return 0;
}
myparm.fileParam.ioNamePtr = myReply->fName;
myparm.fileParam.ioVRefNum = myReply->vRefNum;
myparm.fileParam.ioFVersNum = 0;
myparm.fileParam.ioFDirIndex = 0;
myerr = PBGetFInfo(&myparm, false);
myReply->fName[myReply->fName[0] + 1] = '\0';
/* fullname(pathname, myReply->vRefNum, &myReply->fName[1]); */
SetPort(mydialog);
/* ellipses_path_name( pathname,
(mydialog->portRect.right - mydialog->portRect.left) - 8 ); */
MySetText(mydialog, dtitle1item, &myReply->fName[1]);
if (myerr == noErr) {
sprintf(mystr, "%-4.4s", &myparm.fileParam.ioFlFndrInfo.fdType);
MySetText(mydialog, dtypeitem, mystr);
sprintf(mystr, "%-4.4s", &myparm.fileParam.ioFlFndrInfo.fdCreator);
MySetText(mydialog, dcreatoritem, mystr);
IUTimeString(myparm.fileParam.ioFlCrDat, -1, cstr);
p2cstr(cstr);
IUDateString(myparm.fileParam.ioFlCrDat, 1, mstr);
p2cstr(mstr);
strcat(cstr, " on ");
strcat(cstr, mstr);
IUTimeString(myparm.fileParam.ioFlMdDat, -1, mstr);
p2cstr(mstr);
IUDateString(myparm.fileParam.ioFlMdDat, 1, mystr);
p2cstr(mystr);
strcat(mstr, " on ");
strcat(mstr, mystr);
sprintf(mystr, "Data fork size = %ld bytes.\015",
myparm.fileParam.ioFlLgLen);
sprintf(&mystr[strlen(mystr)], "Resource fork size = %ld bytes.\015",
myparm.fileParam.ioFlRLgLen);
sprintf(&mystr[strlen(mystr)], "Total file size = %ld bytes.\015",
myparm.fileParam.ioFlLgLen + myparm.fileParam.ioFlRLgLen);
sprintf(&mystr[strlen(mystr)], "Created: %s.\015Modified: %s.",
cstr, mstr);
mystr[239] = '\0';
MySetText(mydialog, dtitle2item, mystr);
cparm.hFileInfo.ioCompletion = 0;
cparm.hFileInfo.ioNamePtr = myReply->fName;
cparm.hFileInfo.ioVRefNum = myReply->vRefNum;
cparm.hFileInfo.ioFVersNum = 0;
cparm.hFileInfo.ioFDirIndex = 0;
cparm.hFileInfo.ioDirID = 0;
myerr = PBGetCatInfo(&cparm, (Boolean)false);
myReply->fName[myReply->fName[0]+1] = '\0';
if (myerr == noErr)
sprintf(mystr, "%d", cparm.hFileInfo.ioFlParID);
else
mystr[0] = '\0';
MySetText(mydialog, dfolderitem, mystr);
if ((myparm.fileParam.ioFlAttrib&0x01) != 0) MySetControl(mydialog, rdoItem, 1);
if ((myparm.fileParam.ioFlAttrib&0x08) != 0) MySetControl(mydialog, dataItem, 1);
if ((myparm.fileParam.ioFlAttrib&0x04) != 0) MySetControl(mydialog, rsrcItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x8000) != 0) MySetControl(mydialog, lkdItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x4000) != 0) MySetControl(mydialog, visItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x2000) != 0) MySetControl(mydialog, bunItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x1000) != 0) MySetControl(mydialog, sysItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0800) != 0) MySetControl(mydialog, bozoItem, 1);
/* if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0400) != 0) MySetControl(mydialog, busyItem, 1); */
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0200) != 0) MySetControl(mydialog, chgItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0100) != 0) MySetControl(mydialog, initItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0080) != 0) MySetControl(mydialog, shrItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0040) != 0) MySetControl(mydialog, cachItem, 1);
if ((myparm.fileParam.ioFlFndrInfo.fdFlags&0x0001) != 0) MySetControl(mydialog, dskItem, 1);
}
else
MySetText(mydialog, dtitle2item, "Couldn't open file.\015No additional information.");
SelIText(mydialog, dtypeitem, 0, 8);
for (save=done=false,i=0; ! done; ) {
SetPort(mydialog);
FrameButton(mydialog, 1);
ModalDialog((ModalFilterProcPtr)UniversalFilter, &itemhit);
switch (itemhit) {
case cancel:
done = true; save = true;
break;
case ok:
done = true; save = false;
break;
case lkdItem:
case visItem:
case bozoItem:
case chgItem:
case bunItem:
case dskItem:
case initItem:
case sysItem:
case shrItem:
case cachItem:
case rdoItem:
MySetControl(mydialog, itemhit,
! MyGetControl(mydialog, itemhit));
break;
}
}
if (save) {
myflags = 0;
if (MyGetControl(mydialog, rdoItem))
SetFLock(myReply->fName, myReply->vRefNum);
else
RstFLock(myReply->fName, myReply->vRefNum);
if (MyGetControl(mydialog, lkdItem)) myflags |= 0x8000;
if (MyGetControl(mydialog, visItem)) myflags |= 0x4000;
if (MyGetControl(mydialog, bunItem)) myflags |= 0x2000;
if (MyGetControl(mydialog, sysItem)) myflags |= 0x1000;
if (MyGetControl(mydialog, bozoItem)) myflags |= 0x0800;
/* if (MyGetControl(mydialog, busyItem)) myflags |= 0x0400; */
if (MyGetControl(mydialog, chgItem)) myflags |= 0x0200;
if (MyGetControl(mydialog, initItem)) myflags |= 0x0100;
if (MyGetControl(mydialog, shrItem)) myflags |= 0x0080;
if (MyGetControl(mydialog, cachItem)) myflags |= 0x0040;
if (MyGetControl(mydialog, dskItem)) myflags |= 0x0001;
myparm.fileParam.ioFlFndrInfo.fdFlags = myflags;
MyGetText(mydialog, dtypeitem, mystr);
memcpy(&myparm.fileParam.ioFlFndrInfo.fdType, mystr, 4);
MyGetText(mydialog, dcreatoritem, mystr);
memcpy(&myparm.fileParam.ioFlFndrInfo.fdCreator, mystr, 4);
myparm.fileParam.ioNamePtr = myReply->fName;
myparm.fileParam.ioVRefNum = myReply->vRefNum;
myparm.fileParam.ioFVersNum = 0;
myparm.fileParam.ioFDirIndex = 0;
myerr = PBSetFInfo(&myparm, false);
if (myerr != noErr) {
message_alert("Error #%d setting file information.", myerr);
}
myerr = FlushVol(NULL, myReply->vRefNum);
if (myerr != noErr) {
message_alert("Error #%d flushing volume.", myerr);
}
}
DisposeDialog(mydialog);
SetPort(saveport);
}
#ifdef NEVER_DEFINED
ellipses_path_name(pathname, width)
char *pathname;
int width;
{
int lwidth = 0, rwidth = 0, ewidth = 0;
char lpath[256], *lptr, rpath[256], *rptr;
c2pstr(pathname);
lwidth = StringWidth(pathname);
p2cstr(pathname);
if (lwidth <= width)
return;
ewidth = StringWidth("\p…");
lptr = pathname;
rptr = &pathname[strlen(pathname)];
lpath[0] = '\0';
rpath[0] = '\0';
for ( ; ewidth + lwidth + rwidth <= width ; )
{
for ( ; *lptr && *lptr != ':' ; ++lptr)
;
if (*lptr != ':')
break;
*lptr = '\0';
c2pstr(pathname);
lwidth = StringWidth(pathname);
p2cstr(pathname);
*lptr = ':';
for ( ; rptr > pathname && *rptr != ':' ; --rptr)
;
if (*rptr != ':')
break;
*lptr = '\0';
c2pstr(rptr + 1);
rwidth = StringWidth(rptr + 1);
p2cstr(rptr + 1);
}
if (*lptr == ':' && *rptr == ':' && rptr > lptr)
{
*lptr = '\0';
sprintf(tempstr, "%s:…:%s", pathname, rptr + 1);
strcpy(pathname, tempstr);
*lptr = ':';
}
else if (lptr == rptr)
{
/* leave alone... */
}
else if (*rptr == ':' && rptr < lptr)
{
sprintf(tempstr, "…:%s", rptr + 1);
strcpy(pathname, tempstr);
}
else if (*lptr == ':' && rptr < lptr)
{
sprintf(tempstr, "%s:…:%s", pathname, rptr + 1);
strcpy(pathname, tempstr);
}
else
{
/* leave alone... */
}
}
#endif